<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>

<tiles:insertDefinition name="layout.main">
	<tiles:putAttribute name="body">
	
	<script type="text/javascript">
	function addCityAutocomplete(){
		$("#form_address_city_name").autocomplete({
			source:function(request, response){
				var url = '<s:url action="city-autocomplete" namespace="/autocomplete"/>';
				url = url + '?term=' + $("#form_address_city_name").val();
				$.ajax({
					url : url,
					dataType: 'json',
					success: function(data) {
						response($.map(data, function(item){
								return {
									label : item.name,
									value : item.name,
									name : item.name,
									id : item.id
								};
						}));
					}, 
					error: function() {
						$("#streetTextfield").removeClass('ui-autocomplete-loading');
					}
				});
				
				
				
			},
			minLength: 3,
			select : function(event, ui){
				$('#addressCityId').val(ui.item.id);
				$("#form_address_city_name").val(ui.item.name);
			}
		});
	}
	$(document).ready(function(){
		addCityAutocomplete();
	});
	</script>
	
		<s:form action="register">
			<s:textfield name="username" label="login"/>
			<s:textfield name="age" label="wiek"/>
			<s:select list="sexsList" name="sex" label="płeć" emptyOption="--wybierz--" listKey="name" listValue="label" headerValue="--wybierz--" headerKey=""/>
			<s:password name="password" label="hasło"/>
			<s:textfield id="form_address_city_name" name="city.name" label="miasto"/>
			<s:hidden id="addressCityId" name="city.id"/>
			
			<tr>
			<s:checkboxlist
			list="%{abilitiesList}"
			name="abilities" label="Zdolności:"
			theme="elearning" listKey="name" listValue="label"
			 />
			 </tr>
			<tr>
			<s:checkboxlist
			list="%{characterTraitsList}"
			name="characterTraits" label="Cechy charakteru:"
			theme="elearning" listKey="name" listValue="label"
			 />
			 </tr>
			<tr>
			<s:checkboxlist
			list="%{interestsList}"
			name="interests" label="Zainteresowania:"
			theme="elearning" listKey="name" listValue="label"
			 />
			 </tr>

			
			<s:submit/>
		</s:form>
	
	</tiles:putAttribute>
</tiles:insertDefinition>